﻿//删除提示标题
var delDlgTitle = "温馨提示";
//删除提示内容
var delDlgMsg = "您确认删除选中数据吗？";

//格式化Json日期
function formatDate(value, pattern) {
    try {
        if (value)
            return (eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"))).pattern(pattern);
    }
    catch (e) {
        return value;
    }
}

//动态增加tab页
function addTab(parent, title, url) {
    if ($('#' + parent).tabs('exists', title)) {
        $('#' + parent).tabs('select', title);
    } else {
        var content = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
        $('#' + parent).tabs('add', {
            title: title,
            content: content,
            closable: true
        });
    }
}


//数据字典列表转换成树
function convert(rows) {
    function exists(rows, DictionaryParentID) {
        for (var i = 0; i < rows.total; i++) {
            if (rows.rows[i].DictionaryID == DictionaryParentID) {
                return true;
            }
        }
        return false;
    }
    var nodes = [];
    // get the top level nodes
    for (var i = 0; i < rows.total; i++) {
        var row = rows.rows[i];
        if (!exists(rows, row.DictionaryParentID)) {
            nodes.push({
                rootid: row.DictionaryID,
                id: row.DictionaryCode,
                text: row.DictionaryName
            });
        }
    }
    var toDo = [];
    for (var i = 0; i < nodes.length; i++) {
        toDo.push(nodes[i]);
    }
    while (toDo.length) {
        var node = toDo.shift();// the parent node
        // get the children nodes
        for (var i = 0; i < rows.total; i++) {
            var row = rows.rows[i];
            if (row.DictionaryParentID == node.rootid) {
                var child = { id: row.DictionaryCode, text: row.DictionaryName };
                if (node.children) {
                    node.children.push(child);
                } else {
                    node.children = [child];
                }
                toDo.push(child);
            }
        }
    }
    return nodes;
}